home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / pcw.zip / PCDELAY.ASM < prev    next >
Assembly Source File  |  1991-12-16  |  4KB  |  82 lines

  1.               Title _delay.Asm
  2.               Page ,120
  3. ;****************************************************************
  4. ;* File Id.                       Delay.Asm                     *
  5. ;* Author.                        Stan Milam.                   *
  6. ;* Date Written.                  06/12/89.                     *
  7. ;*                                                              *
  8. ;*             (c) Copyright 1989, 1990 by Stan Milam           *
  9. ;*                                                              *
  10. ;* NOTE: This file is assembled with Micorsoft MASM 5.10, but   *
  11. ;* Borland's Turbo Assembler can be used too.                   *
  12. ;****************************************************************
  13. ;
  14. Gate          Equ       61h
  15. Timer2        Equ       42h
  16. Cntl          Equ       43h
  17. Mode3         Equ       0b6h
  18. Factor        Equ       1193
  19. Range         Equ       7
  20.  
  21.               Dosseg                        ;Use standard segmentation
  22.               .Model Huge
  23.  
  24.               .Code
  25.               Page
  26. ;************************************************************
  27. ;*                          _Delay                          *
  28. ;*                                                          *
  29. ;* This procedure will program channel two of the 8253 timer*
  30. ;* chip to create a very accurate delay routine.  Can not   *
  31. ;* use this routine in conjuction with sound routines as    *
  32. ;* they use channel two to create square wave frequencies   * 
  33. ;* sound.                                                   *
  34. ;                                                           *
  35. ;* void __delay(unsigned milliseconds);                     *
  36. ;************************************************************
  37.               Public    _delay
  38. _delay        Proc      Far
  39.               Push      Bp              ;Set up the stack frame
  40.               Mov       Bp,Sp
  41.               Push      Ax              ;Save the registers
  42.               Push      Bx
  43.               Push      Cx
  44.               Push      Dx
  45.               Xor       Cx,Cx           ;Clear the counter
  46.               Mov       Bx,[Bp+6]       ;Get the number of milliseconds
  47.               Mov       Dx,Gate         ;Gate port
  48.               In        Al,Dx           ;Get in Gate value
  49.               Or        Al,01h          ;Open Gate to system timer chnl 2
  50.               Out       Dx,Al           ;Put it 
  51.               Mov       Dx,Cntl         ;Timer Control register
  52.               Mov       Al,Mode3        ;Mode 3,r/w,lsb,msb,binary
  53.               Out       Dx,Al           ;
  54.               Mov       Dx,Timer2       ;Timer 2 port
  55.               Mov       Ax,Factor       ;System timer 1.19mhz-1/1000
  56.               Out       Dx,Al           ;Send low byte
  57.               Mov       Al,Ah           ;Get msb ready
  58.               Out       Dx,Al           ;Send high byte
  59. MT_Loop:
  60.               In        Al,Dx           ;Read lsb count from latch
  61.               Mov       Ah,Al           ;Put it in Ah
  62.               In        Al,Dx           ;Read msb count from latch
  63.               Xchg      Ah,Al           ;Reverse them for full word value
  64.               Cmp       Ax,Range        ;Is the count < Range
  65.               Jg        MT_Loop         ;No - keep looking
  66.               Inc       Cx              ;Count < range increment our count
  67.               Cmp       Bx,Cx           ;Our count reached max yet?
  68.               Jnz       MT_Loop         ;No - keep on keeping on
  69.               Mov       Dx,Gate         ;Reset the open Gate
  70.               In        Al,Dx           ;Read in Gate Value
  71.               And       Al,0fch         ;Mask off two lowest bits
  72.               Out       Dx,Al           ;Close the Gate
  73.               Pop       Dx              ;Restore the registers
  74.               Pop       Cx
  75.               Pop       Bx
  76.               Pop       Ax
  77.               Pop       Bp
  78.               Ret
  79. _delay        Endp
  80.               End
  81. 
  82.